package cn.itcast.hotel.config;

import cn.itcast.hotel.constant.MqConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MqConfiguration {

    @Bean
    public Queue hotelDeleteQueue(){
        return new Queue(MqConstants.HOTEL_DELETE_QUEUE);
    }

    @Bean
    public Queue hotelInsertQueue(){
        return new Queue(MqConstants.HOTEL_INSERT_QUEUE);
    }

    @Bean
    public TopicExchange hotelTopicExchange() {
        return ExchangeBuilder.topicExchange(MqConstants.HOTEL_EXCHANGE)
                .build();
    }

    @Bean
    public Binding hotelInsertQueueBindingHotelTopicExchange() {
        return BindingBuilder.bind(hotelInsertQueue())
                .to(hotelTopicExchange())
                .with(MqConstants.HOTEL_INSERT_KEY);
    }

    @Bean
    public Binding hotelDeleteQueueBindingHotelTopicExchange() {
        return BindingBuilder.bind(hotelDeleteQueue())
                .to(hotelTopicExchange())
                .with(MqConstants.HOTEL_DELETE_KEY);
    }
}
